#ifndef _QY_URL_CONNECTION_H
#define _QY_URL_CONNECTION_H

#include "URLRequest.h"
#include "URLResponse.h"
#include "Thread.h"

namespace qy
{

enum ConnectionStatus 
{
    CONNECTED = 0,
    DISCONNECTED = 1,
    TIMEOUT = 2
};

typedef void (*URLConnectionCallback)(const URLResponse &response, ConnectionStatus status);

class URLConnection : public Thread
{
public:
    URLConnection(const URLRequest &request, URLConnectionCallback callbak);
    virtual ~URLConnection();

    bool close();
    ConnectionStatus status();

protected:

    int run();

protected:
    URLConnectionCallback m_callback;
    URLRequest m_request;
    URLResponse m_response;
    ConnectionStatus m_status;
};

}
#endif
